package weWork;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;

import java.util.ArrayList;
import java.util.List;

public class AppPage extends BasePage {

    public AppPage(WebDriver driver) {
        super(driver);
    }

    public ContactPage toContact(){
        driver.findElement(By.linkText("通讯录")).click();
        return new ContactPage(driver);
    }

    public AppPage addNotice(String title,String writer,String content) throws InterruptedException {

        driver.findElement(By.linkText("发公告")).click();

        driver.findElement(By.xpath("//*[@class='msg_infoItem_infoInit']//*[@class='msg_create_infoItem_selectScope js_select_range_btn']")).click();
        Thread.sleep(1000);
        driver.findElement(By.xpath("//*[@class='ww_dialog_foot_left']//*[@d_ck='checkAll']")).click();
        Thread.sleep(1000);
        driver.findElement(By.xpath("//*[@class='qui_dialog_foot ww_dialog_foot']//*[@d_ck='submit']")).click();
        Thread.sleep(1000);

        driver.findElement(By.xpath("//*[@class='ww_compatibleTxt ww_editorTitleWrap']//*[@placeholder='在此输入标题']")).sendKeys(title);
        Thread.sleep(1000);

//未定位到公告内容元素
        ((JavascriptExecutor)driver).executeScript("document.getElementsByTagName('p')[0].value='123'");
        ((JavascriptExecutor)driver).executeScript("return document.getElementsByTagName('p')[0].value");


        Thread.sleep(1000);
        driver.findElement(By.xpath("//*[@class='msg_infoItem msg_create_infoItem msg_create_noticeBlockElem']//*[@placeholder='请填写发布者']")).sendKeys(writer);
        Thread.sleep(1000);

        driver.findElement(By.xpath("//*[@class='frame_cnt_innerStage msg_create_stage']//*[@class='qui_btn ww_btn ww_btn_Blue js_save_send js_disabled_item']")).click();
        driver.findElement(By.linkText("确定")).click();
        return this;
    }
    public List<String> getNoticList(){
        List<String> notice=new ArrayList<>();
        driver.findElements(By.cssSelector("#messageListContent td.msg_history_msgList_td.msg_history_msgList_td_title > span")).forEach(e->{
            notice.add(e.getText());
        });
        return notice;

    }


}
